import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';


class MyChromeSafariBrowser extends ChromeSafariBrowser {
  @override
  void onOpened() {
    print("ChromeSafari browser opened");
  }

  @override
  void onCompletedInitialLoad(didLoadSuccessfully) {
    print("ChromeSafari browser initial load completed");
  }

  @override
  void onClosed() {
    print("ChromeSafari browser closed");
  }
}

class ChromeSafariBrowserExampleScreen extends StatefulWidget {
  final ChromeSafariBrowser browser = MyChromeSafariBrowser();

  late String urlStr;

  ChromeSafariBrowserExampleScreen(this.urlStr);

  @override
  _ChromeSafariBrowserExampleScreenState createState() =>
      _ChromeSafariBrowserExampleScreenState();
}

class _ChromeSafariBrowserExampleScreenState
    extends State<ChromeSafariBrowserExampleScreen> {
  @override
  void initState() {
    openWebView();
    super.initState();
  }

  openWebView()async{
    await widget.browser.open(
      // url: WebUri("http://49.234.222.178:9097/index?res_model=documents.document&res_id=0&res_field=&company_id=1&create_uid=2&write_uid=2&access_token=430f89381edac608ea51365d4d7403dc&folder_id=13&name=file&offset=10"),
        url: WebUri(widget.urlStr),
        settings: ChromeSafariBrowserSettings(
            shareState: CustomTabsShareState.SHARE_STATE_OFF,
            isSingleInstance: false,
            isTrustedWebActivity: false,
            keepAliveEnabled: true,
            startAnimations: [
              AndroidResource.anim(
                  name: "slide_in_left", defPackage: "android"),
              AndroidResource.anim(
                  name: "slide_out_right", defPackage: "android")
            ],
            exitAnimations: [
              AndroidResource.anim(
                  name: "abc_slide_in_top",
                  defPackage:
                  "com.pichillilorenzo.flutter_inappwebviewexample"),
              AndroidResource.anim(
                  name: "abc_slide_out_top",
                  defPackage:
                  "com.pichillilorenzo.flutter_inappwebviewexample")
            ],
            dismissButtonStyle: DismissButtonStyle.CLOSE,
            presentationStyle:
            ModalPresentationStyle.OVER_FULL_SCREEN));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
}
